home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / BuildingBlocks / WriteLineWindow.p < prev    next >
Encoding:
Text File  |  1995-07-28  |  5.7 KB  |  155 lines  |  [TEXT/MPS ]

  1. {
  2.     File:        WriteLineWindow.p
  3.  
  4.     Contains:    Routines to create and handle a scrollable transcript-type window.
  5.                 The expected use of this unit is for a 'debugging' window in an
  6.                 application.
  7.                 
  8.                 This unit hooks into the MPW 3.2 i/o hooks, so that once the debugging
  9.                 window is created, all output from Pascal writeln and C printf statements
  10.                 will be placed into this window.
  11.                 
  12.     How to use:
  13.                 At the start of your application, call WWInit() and WWNew() or WWNewDefault.
  14.                 This will create and show the debugging window.  In the main event loop,
  15.                 call WWEvent() after you get an event but before you handle it.  If this
  16.                 function returns true, then it was an event associated with the debugging
  17.                 window and should be 'ignored' by your application.
  18.  
  19.                 If you want all information sent to the window also written to a file,
  20.                 call WWRedirect() or WWFSpRedirect.
  21.                 
  22.                 To temporarily suspend output from you application, call the WWForce()
  23.                 function.  This saves the current options on a stack and uses the new
  24.                 ones.  When you are ready to restore the old options, call WWEndForce().
  25.                 
  26.                 You can call WWAddText() to add text to the window directly.
  27.                 
  28.     Caveats:    Since the window routines use global data, you can't have more than
  29.                 one transcript window in an application.  These routines also can't be
  30.                 used in stand-alone code resources (although I do have a similar unit that
  31.                 can be used from stand-alone code - KSS)
  32.  
  33.     Written by:    Bruce Horn, Steve Capps, Larry Kenyon,
  34.                 John Meier, scott douglass, Darin Adler,
  35.                 Paul Mercer, Bryan Stearns, Dave Owens
  36.     
  37.     Stolen from the Finder by: Keith Stattenfield
  38.  
  39.     Copyright:    © 1990, 1991 by Apple Computer, Inc., all rights reserved.
  40.  
  41.     Change History:
  42.  
  43.         11/25/91    KSS        Add WWFLUSHOUTPUTFILE defn.
  44.  
  45.                  7/25/91    KSS        Added WWNewDefault, WWFSpRedirect, some primitives to insert 
  46.                                      and a few 'standard' data types into the window.  Wrote the 
  47.                                     Contains: and How to use: sections of this header.
  48.  
  49.          <5>    10/16/90    sad        fix WWRedirect
  50.          <4>      8/3/90    pm        use NewHandleSys instead of NewHandle to make the memory
  51.                                     difference between debug & SCM builds smaller
  52.         <2+>     3/21/90    prp        Debug window's line array memory is allocated by NewHandleClear
  53.                                     instead NewHandle.
  54.  
  55.     To Do:
  56. }
  57.  
  58. UNIT WriteLineWindow;
  59.     {lifted from MacApp's WriteLnWindow}
  60.     {Copyright 1985, 1986 Apple Computer, Inc}
  61.  
  62. INTERFACE
  63.  
  64. {$R-} {$D+}
  65.  
  66. USES
  67.      MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, PasLibIntf, Files, Folders, SysEqu;
  68.  
  69. CONST
  70.     kWWEol = CHR($0D);
  71.     kForceDepth = 10;
  72.  
  73. TYPE
  74.     WrForceOptions = (forceOn, forceOff, forceUnchanged);
  75.  
  76. VAR
  77. {$Z+}
  78.     gDebugWindowPtr:    WindowPtr;
  79. {$Z-}
  80.     gWrToWindow:        BOOLEAN;    {set to TRUE to enable writelns to window}
  81.     gWrToFile:            BOOLEAN;    {set to TRUE to enable writelns to file}
  82.         {both are initialized to TRUE in WWInit}
  83.  
  84. {All public procedure begin with WW (for WritelnWindow)}
  85. PROCEDURE WWInit(numLines, numCharsPerLine: INTEGER);
  86.     {Call this once at the start of your program.}
  87.  
  88. PROCEDURE WWNew(bounds: Rect; windowTitle: Str255; goAway: BOOLEAN; visible: BOOLEAN;
  89.                 outputFont, outputSize: INTEGER);
  90.     {Call this to create a WriteLn window with given title.
  91.         goAway is TRUE iff you want a go away box (IF the user clicks the go away box,
  92.             the window will be hidden but not freed);
  93.         visible is TRUE iff you want the window to be visible initially;
  94.         outputFont & output size define the font to use
  95.         }
  96.  
  97. PROCEDURE WWNewDefault;
  98. PROCEDURE WWShowWindow;
  99.  
  100. PROCEDURE WWForceOutput(wrToWindow, wrToFile: WrForceOptions);
  101. PROCEDURE WWEndForce;
  102.     {Since it is now possible that one part of the program disables writelns to the window, you
  103.         might want to guarantee that certain writelns appear in the window.  WWForceOutput saves
  104.         the values of gWrToWindow & gWrToFile on a stack (depth = kForceDepth), and sets
  105.         these values according to the parameters.  WWEndForce simply pops the stack.}
  106.  
  107. FUNCTION  WWRedirect(vRefNum: INTEGER; fileName: Str255): OSErr;
  108.     {IF you call this, THEN subsequent writelns will be sent to the indicated file.  (Assuming
  109.         writing to the file is enabled. Pass '' for the fileName to close any open file.
  110.         To append output to an existing file, place the characters '>>' at the start of the filename. }
  111.  
  112. {    This uses the FSSpec record introduced with MPW 3.2.  A special case is that, if the vRefNum and
  113.     the parID of the redirectFile are 0, then the file will be created in the current System Folder. }
  114. FUNCTION WWFSpRedirect (redirectFile : FSSpec; appendToExistingFile : boolean) : OSErr;
  115.  
  116. FUNCTION  WWReadCh: CHAR;
  117. FUNCTION  WWReadLn(buffer: Ptr; byteCount: INTEGER): LONGINT;
  118. PROCEDURE WWAddText(textBuf: Ptr; byteCount: longint);
  119.  
  120.     {Call before SizeWindow if you need to resize the debug window programmatically}
  121. PROCEDURE WWInvalGrowBox;
  122.     {Call after SizeWindow if you need to resize the debug window programmatically}
  123. PROCEDURE WWGrown;
  124.  
  125.     {Call the following procedures in response to events for the WriteLnWindow.
  126.         (Test the window receiving the event against gDebugWindowPtr.}
  127. PROCEDURE WWActivateEvent(modifiers: INTEGER);
  128. PROCEDURE WWMouseDown(where: INTEGER; pt: Point; modifiers: INTEGER);
  129. PROCEDURE WWUpdateEvent;
  130. PROCEDURE WWScroll(howManyLines: INTEGER); {for UTrace use; negative arg scrolls backwards}
  131.  
  132. PROCEDURE IDUWritelnWindow; {Writeln UWritelnWindow's compile time.}
  133.  
  134. FUNCTION WWFirstLGlob: LongInt;
  135. FUNCTION WWLastLGlob: LongInt;
  136. FUNCTION WWFirstGlob: LongInt;
  137. FUNCTION WWLastGlob: LongInt;
  138.  
  139. Function WWEvent(event: EventRecord): Boolean;
  140.  
  141. { Keith's added convenience routines }
  142. PROCEDURE WWAddDate;
  143. PROCEDURE WWAddTime;
  144. PROCEDURE WWAddDateTime;
  145. PROCEDURE WWAddEncodedText (dataPtr : UNIV Ptr; dataSize : integer);
  146. PROCEDURE WWAddHexData (dataPtr : UNIV Ptr; dataSize : integer);
  147.  
  148. PROCEDURE WWFlushOutputFile;
  149.  
  150. IMPLEMENTATION
  151.  
  152. {$I WriteLineWindow.inc1.p }
  153.  
  154. END.
  155.